from mongokit import *
import datetime, re

class Package(Document):
    structure = {
        'name':unicode,
        'version':unicode,
        'description':unicode,
        'author':unicode,
        'email':unicode,
        'date_creation':datetime.datetime,
        'dependencies':[{'name':unicode, 'version':unicode}]
    }
    use_dot_notation=True

    validators = {
        'version': lambda x: re.match(r'^\d+(\.\d+){1,2}$', x) != None
    }

    requireed_fields = ['name','version']

    default_values = {
        'date_creation':datetime.datetime.utcnow
    }
